package com.learning.db.newfunction;

import com.google.common.base.Joiner;
import lombok.Getter;
import lombok.Setter;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * ClassName: CusBean
 * Description:
 * Date: 2018/4/4 9:46 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Setter
@Getter
public class CusBean implements WritableComparable<CusBean> {

    private static final Joiner JOINER = Joiner.on("|");

    /**
     * 个人编号
     */
    private String aac999 = "";
    /**
     * 医疗结算事件id
     */
    private String cka009 = "";
    /**
     * 自负金额
     */
    private String akc254 = "0";
    /**
     * 累计自负费用
     */
    private String sumAkc254 = "0";
    /**
     * 本次自负赔付
     */
    private String akc254Compensate = "0";

    /**
     * 累计自负赔付
     */
    private String sumAkc254Compensate = "0";

    /**
     * 合规自费金额(取小后的本次合规自费费用)
     */
    private String complianceOwnExpense = "0";
    /**
     * 累计合规费用
     */
    private String sumComplianceOwnExpense = "0";

    /**
     * 自负+合规自费
     */
    private String akc254AddComplianceOwnExpense = "0";

    /**
     * 自负+合规自费 累计(累计自负费用+累计合规费用)
     */
    private String sumAkc254AddComplianceOwnExpense = "0";
    /**
     * 本次自负加合规赔付
     */
    private String akc254AddCOECompensate = "0";
    /**
     * 累计自负加合规赔付
     */
    private String sumAkc254AddCOECompensate = "0";


    /**
     * 结算日期
     */
    private String cke011 = "";
    /**
     * 当前日期时间
     */
    private String today = "";


    /**
     * 救助标识
     */
    private String ckc005;

    /**
     * 区分本期数据与往期数据
     * 1-本期 0-往期
     */
    private int flag;

    @Override
    public int compareTo(CusBean o) {
        int compare = this.aac999.compareToIgnoreCase(o.getAac999());
        return compare == 0 ? (cke011.compareTo(o.getCke011()) == 0 ? cka009.compareTo(o.getCka009()) : cke011.compareTo(o.getCke011())) : compare;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(this.aac999);
        out.writeUTF(this.cka009);
        out.writeUTF(this.akc254);
        out.writeUTF(this.sumAkc254);
        out.writeUTF(this.akc254Compensate);

        out.writeUTF(this.sumAkc254Compensate);
        out.writeUTF(this.complianceOwnExpense);
        out.writeUTF(this.sumComplianceOwnExpense);
        out.writeUTF(this.akc254AddComplianceOwnExpense);
        out.writeUTF(this.sumAkc254AddComplianceOwnExpense);
        out.writeUTF(this.akc254AddCOECompensate);

        out.writeUTF(this.sumAkc254AddCOECompensate);
        out.writeUTF(this.cke011);
        out.writeUTF(this.ckc005);
        out.writeInt(this.flag);

    }

    @Override
    public void readFields(DataInput in) throws IOException {

        this.aac999 = in.readUTF();
        this.cka009 = in.readUTF();
        this.akc254 = in.readUTF();
        this.sumAkc254 = in.readUTF();
        this.akc254Compensate = in.readUTF();

        this.sumAkc254Compensate = in.readUTF();
        this.complianceOwnExpense = in.readUTF();
        this.sumComplianceOwnExpense = in.readUTF();
        this.akc254AddComplianceOwnExpense = in.readUTF();
        this.sumAkc254AddComplianceOwnExpense = in.readUTF();
        this.akc254AddCOECompensate = in.readUTF();

        this.sumAkc254AddCOECompensate = in.readUTF();
        this.cke011 = in.readUTF();
        this.ckc005 = in.readUTF();
        this.flag = in.readInt();

    }

    @Override

    public String toString() {
        return JOINER.join(String.format("%-10s", aac999), String.format("%-16s", cka009), String.format("%-17s", akc254), String.format("%-17s", sumAkc254), String.format("%-17s", akc254Compensate),
                String.format("%-17s", sumAkc254Compensate), String.format("%-17s", complianceOwnExpense), String.format("%-17s", sumComplianceOwnExpense),
                String.format("%-17s", sumAkc254AddComplianceOwnExpense),
                String.format("%-17s", akc254AddCOECompensate), String.format("%-17s", sumAkc254AddCOECompensate), String.format("%-14s", cke011), String.format("%-8s", today));
    }

    public void loadDate(String[] arr) {

        this.aac999 = arr[0];
        this.cka009 = arr[1];
        this.akc254 = arr[2];
        this.sumAkc254 = arr[3];
        this.complianceOwnExpense = arr[4];
        this.sumComplianceOwnExpense = arr[5];
        this.akc254AddComplianceOwnExpense = arr[6];
        this.sumAkc254AddComplianceOwnExpense = arr[7];
        this.ckc005 = arr[8];
        this.cke011 = arr[9];
    }
}
